import request from '@/utils/request'
//引入返回值类型
import type { CategoryResponse, CategoryAttrResponse, Attr } from './type'
enum API {
  //获取一级分类
  Category1_URL = '/admin/product/getCategory1',
  //获取二级分类
  Category2_URL = '/admin/product/getCategory2/',
  //获取三级分类
  Category3_URL = '/admin/product/getCategory3/',
  //根据分类获取属性列表接口
  GetAttr_URL = '/admin/product/attrInfoList/',
  //新增属性接口
  AddAttr_URL = '/admin/product/saveAttrInfo',
  //删除属性接口
  DeleteAttr_URL = '/admin/product/deleteAttr/',
}
//获取一级分类
export const GetC1 = () => request.get<any, CategoryResponse>(API.Category1_URL)
//获取二级分类
export const GetC2 = (id: number | string) =>
  request.get<any, CategoryResponse>(API.Category2_URL + id)
//获取三级分类
export const GetC3 = (id: number | string) =>
  request.get<any, CategoryResponse>(API.Category3_URL + id)
//根据分类获取属性列表
export const GetAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, CategoryAttrResponse>(
    API.GetAttr_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )
//新增属性
export const AddOrUpdateAttr = (data: Attr) =>
  request.post(API.AddAttr_URL, data)

//删除属性
export const DeleteAttr = (id: number) =>
  request.delete(API.DeleteAttr_URL + id)
